home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zimage2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  5.2 KB  |  173 lines

  1. /* Copyright (C) 1992, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zimage2.c,v 1.3 2000/09/19 19:00:54 lpd Exp $ */
  20. /* image operator extensions for Level 2 PostScript */
  21. #include "math_.h"
  22. #include "memory_.h"
  23. #include "ghost.h"
  24. #include "oper.h"
  25. #include "gscolor.h"
  26. #include "gscspace.h"
  27. #include "gscolor2.h"
  28. #include "gsmatrix.h"
  29. #include "gsimage.h"
  30. #include "gxfixed.h"
  31. #include "idict.h"
  32. #include "idparam.h"
  33. #include "iimage.h"
  34. #include "iimage2.h"
  35. #include "ilevel.h"
  36. #include "igstate.h"        /* for igs */
  37.  
  38. /* Extract and check the parameters for a gs_data_image_t. */
  39. int
  40. data_image_params(const ref *op, gs_data_image_t *pim,
  41.           image_params *pip, bool require_DataSource,
  42.           int num_components, int max_bits_per_component)
  43. {
  44.     int code;
  45.     int decode_size;
  46.     ref *pds;
  47.  
  48.     check_type(*op, t_dictionary);
  49.     check_dict_read(*op);
  50.     if ((code = dict_int_param(op, "Width", 0, max_int_in_fixed / 2,
  51.                    -1, &pim->Width)) < 0 ||
  52.     (code = dict_int_param(op, "Height", 0, max_int_in_fixed / 2,
  53.                    -1, &pim->Height)) < 0 ||
  54.     (code = dict_matrix_param(op, "ImageMatrix",
  55.                   &pim->ImageMatrix)) < 0 ||
  56.     (code = dict_bool_param(op, "MultipleDataSources", false,
  57.                 &pip->MultipleDataSources)) < 0 ||
  58.     (code = dict_int_param(op, "BitsPerComponent", 1,
  59.                    max_bits_per_component, -1,
  60.                    &pim->BitsPerComponent)) < 0 ||
  61.     (code = decode_size = dict_floats_param(op, "Decode",
  62.                         num_components * 2,
  63.                         &pim->Decode[0], NULL)) < 0 ||
  64.     (code = dict_bool_param(op, "Interpolate", false,
  65.                 &pim->Interpolate)) < 0
  66.     )
  67.     return code;
  68.     pip->pDecode = &pim->Decode[0];
  69.     /* Extract and check the data sources. */
  70.     if ((code = dict_find_string(op, "DataSource", &pds)) <= 0) {
  71.     if (require_DataSource)
  72.         return (code < 0 ? code : gs_note_error(e_rangecheck));
  73.     return 1;        /* no data source */
  74.     }
  75.     if (pip->MultipleDataSources) {
  76.     check_type_only(*pds, t_array);
  77.     if (r_size(pds) != num_components)
  78.         return_error(e_rangecheck);
  79.     memcpy(&pip->DataSource[0], pds->value.refs,
  80.            sizeof(ref) * num_components);
  81.     } else
  82.     pip->DataSource[0] = *pds;
  83.     return 0;
  84. }
  85.  
  86. /* Extract and check the parameters for a gs_pixel_image_t. */
  87. int
  88. pixel_image_params(i_ctx_t *i_ctx_p, const ref *op, gs_pixel_image_t *pim,
  89.            image_params *pip, int max_bits_per_component)
  90. {
  91.     int num_components =
  92.     gs_color_space_num_components(gs_currentcolorspace(igs));
  93.     int code;
  94.  
  95.     if (num_components < 1)
  96.     return_error(e_rangecheck);    /* Pattern space not allowed */
  97.     pim->ColorSpace = gs_currentcolorspace(igs);
  98.     code = data_image_params(op, (gs_data_image_t *) pim, pip, true,
  99.                  num_components, max_bits_per_component);
  100.     if (code < 0)
  101.     return code;
  102.     pim->format =
  103.     (pip->MultipleDataSources ? gs_image_format_component_planar :
  104.      gs_image_format_chunky);
  105.     return dict_bool_param(op, "CombineWithColor", false,
  106.                &pim->CombineWithColor);
  107. }
  108.  
  109. /* <dict> .image1 - */
  110. private int
  111. zimage1(i_ctx_t *i_ctx_p)
  112. {
  113.     os_ptr op = osp;
  114.     gs_image_t image;
  115.     image_params ip;
  116.     int code;
  117.  
  118.     gs_image_t_init(&image, gs_currentcolorspace(igs));
  119.     code = pixel_image_params(i_ctx_p, op, (gs_pixel_image_t *)&image, &ip,
  120.                   12);
  121.     if (code < 0)
  122.     return code;
  123.     return zimage_setup(i_ctx_p, (gs_pixel_image_t *)&image, &ip.DataSource[0],
  124.             image.CombineWithColor, 1);
  125. }
  126.  
  127. /* <dict> .imagemask1 - */
  128. private int
  129. zimagemask1(i_ctx_t *i_ctx_p)
  130. {
  131.     os_ptr op = osp;
  132.     gs_image_t image;
  133.     image_params ip;
  134.     int code;
  135.  
  136.     gs_image_t_init_mask_adjust(&image, false,
  137.                 gs_incachedevice(igs) != CACHE_DEVICE_NONE);
  138.     code = data_image_params(op, (gs_data_image_t *) & image, &ip, true, 1, 1);
  139.     if (code < 0)
  140.     return code;
  141.     if (ip.MultipleDataSources)
  142.     return_error(e_rangecheck);
  143.     return zimage_setup(i_ctx_p, (gs_pixel_image_t *)&image, &ip.DataSource[0],
  144.             true, 1);
  145. }
  146.  
  147. /*
  148.  * Process an image that has no explicit source data.  This isn't used by
  149.  * standard Level 2, but it's a very small procedure and is needed by
  150.  * both zdps.c and zdpnext.c.
  151.  */
  152. int
  153. process_non_source_image(i_ctx_t *i_ctx_p, const gs_image_common_t * pic,
  154.              client_name_t cname)
  155. {
  156.     gx_image_enum_common_t *pie;
  157.     int code = gs_image_begin_typed(pic, igs, false /****** WRONG ******/ ,
  158.                     &pie);
  159.  
  160.     /* We didn't pass any data, so there's nothing to clean up. */
  161.     return code;
  162. }
  163.  
  164. /* ------ Initialization procedure ------ */
  165.  
  166. const op_def zimage2_l2_op_defs[] =
  167. {
  168.     op_def_begin_level2(),
  169.     {"1.image1", zimage1},
  170.     {"1.imagemask1", zimagemask1},
  171.     op_def_end(0)
  172. };
  173.